#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
	static bool cmp(vector<int>& a, vector<int>& b)
	{
		return a[0] < b[0];
	}
	vector<vector<int>> merge(vector<vector<int>>& intervals) {
		if (intervals.size() == 1) return intervals;
		vector<vector<int>> result;
		sort(intervals.begin(), intervals.end(), cmp);
		// for(int i=0; i<intervals.size(); i++)
		// {
		//     cout << intervals[i][0] << endl;
		// }
		int begin = intervals[0][0];
		vector<int> tmp(2);
		for (int i = 1; i < intervals.size(); i++)
		{
			if (intervals[i][0] <= intervals[i - 1][1])
			{
				intervals[i][1] = max(intervals[i][1], intervals[i - 1][1]);
			}
			else
			{
				tmp[0] = begin;
				tmp[1] = intervals[i - 1][1];
				result.push_back(tmp);
				begin = intervals[i][0];
			}
		}
		tmp[0] = begin;
		tmp[1] = intervals[intervals.size() - 1][1];
		result.push_back(tmp);
		return result;
	}
};